package com.kingdee.eas.custom.jiu.app;

import java.rmi.RemoteException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.rpc.ServiceException;

import org.apache.log4j.Logger;

import shaded.org.apache.parquet.it.unimi.dsi.fastutil.objects.ObjectCollection;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.metadata.bot.BOTRelationCollection;
import com.kingdee.bos.metadata.bot.BOTRelationFactory;
import com.kingdee.bos.metadata.bot.BOTRelationInfo;
import com.kingdee.bos.metadata.bot.IBOTRelation;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.bos.metadata.entity.SelectorItemInfo;
import com.kingdee.bos.orm.ORMCoreException;
import com.kingdee.bos.rpc.RPCEngine;
import com.kingdee.bos.rpcwrapper.RPCEngineFactory;
import com.kingdee.bos.sql.ParserException;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.base.permission.UserFactory;
import com.kingdee.eas.base.permission.UserInfo;
import com.kingdee.eas.basedata.assistant.AccountBankCollection;
import com.kingdee.eas.basedata.assistant.AccountBankFactory;
import com.kingdee.eas.basedata.assistant.AccountBankInfo;
import com.kingdee.eas.basedata.assistant.CurrencyFactory;
import com.kingdee.eas.basedata.assistant.CurrencyInfo;
import com.kingdee.eas.basedata.assistant.IAccountBank;
import com.kingdee.eas.basedata.assistant.ICurrency;
import com.kingdee.eas.basedata.master.account.AccountControlAttribute;
import com.kingdee.eas.basedata.master.account.AccountPLType;
import com.kingdee.eas.basedata.master.account.AccountTableFactory;
import com.kingdee.eas.basedata.master.account.AccountTableInfo;
import com.kingdee.eas.basedata.master.account.AccountTypeCollection;
import com.kingdee.eas.basedata.master.account.AccountTypeFactory;
import com.kingdee.eas.basedata.master.account.AccountTypeInfo;
import com.kingdee.eas.basedata.master.account.AccountViewCollection;
import com.kingdee.eas.basedata.master.account.AccountViewFactory;
import com.kingdee.eas.basedata.master.account.AccountViewInfo;
import com.kingdee.eas.basedata.master.account.AccountingCurrencyEnum;
import com.kingdee.eas.basedata.master.account.BalanceDirectionEnum;
import com.kingdee.eas.basedata.master.account.IAccountTable;
import com.kingdee.eas.basedata.master.account.IAccountType;
import com.kingdee.eas.basedata.master.account.IAccountView;
import com.kingdee.eas.basedata.master.auxacct.AssistantHGFactory;
import com.kingdee.eas.basedata.master.auxacct.AssistantHGInfo;
import com.kingdee.eas.basedata.master.auxacct.AsstAccountCollection;
import com.kingdee.eas.basedata.master.auxacct.AsstAccountFactory;
import com.kingdee.eas.basedata.master.auxacct.AsstAccountInfo;
import com.kingdee.eas.basedata.master.auxacct.AsstActGroupDetailCollection;
import com.kingdee.eas.basedata.master.auxacct.AsstActGroupDetailFactory;
import com.kingdee.eas.basedata.master.auxacct.AsstActGroupDetailInfo;
import com.kingdee.eas.basedata.master.auxacct.AsstActType;
import com.kingdee.eas.basedata.master.auxacct.AsstActTypeCollection;
import com.kingdee.eas.basedata.master.auxacct.AsstActTypeFactory;
import com.kingdee.eas.basedata.master.auxacct.AsstActTypeInfo;
import com.kingdee.eas.basedata.master.auxacct.GeneralAsstActTypeCollection;
import com.kingdee.eas.basedata.master.auxacct.GeneralAsstActTypeFactory;
import com.kingdee.eas.basedata.master.auxacct.GeneralAsstActTypeGroupCollection;
import com.kingdee.eas.basedata.master.auxacct.GeneralAsstActTypeGroupFactory;
import com.kingdee.eas.basedata.master.auxacct.GeneralAsstActTypeGroupInfo;
import com.kingdee.eas.basedata.master.auxacct.GeneralAsstActTypeInfo;
import com.kingdee.eas.basedata.master.auxacct.IAssistantHG;
import com.kingdee.eas.basedata.master.auxacct.IAsstAccount;
import com.kingdee.eas.basedata.master.auxacct.IAsstActGroupDetail;
import com.kingdee.eas.basedata.master.auxacct.IAsstActType;
import com.kingdee.eas.basedata.master.auxacct.IGeneralAsstActType;
import com.kingdee.eas.basedata.master.auxacct.IGeneralAsstActTypeGroup;
import com.kingdee.eas.basedata.master.auxacct.ShareTacticEnum;
import com.kingdee.eas.basedata.master.cssp.CSSPGroup;
import com.kingdee.eas.basedata.master.cssp.CSSPGroupCollection;
import com.kingdee.eas.basedata.master.cssp.CSSPGroupFactory;
import com.kingdee.eas.basedata.master.cssp.CSSPGroupInfo;
import com.kingdee.eas.basedata.master.cssp.CSSPGroupStandardCollection;
import com.kingdee.eas.basedata.master.cssp.CSSPGroupStandardFactory;
import com.kingdee.eas.basedata.master.cssp.CSSPGroupStandardInfo;
import com.kingdee.eas.basedata.master.cssp.CustomerCompanyInfoInfo;
import com.kingdee.eas.basedata.master.cssp.ISupplier;
import com.kingdee.eas.basedata.master.cssp.ISupplierCompanyInfo;
import com.kingdee.eas.basedata.master.cssp.ISupplierGroupDetail;
import com.kingdee.eas.basedata.master.cssp.SupplierCollection;
import com.kingdee.eas.basedata.master.cssp.SupplierCompanyInfo;
import com.kingdee.eas.basedata.master.cssp.SupplierCompanyInfoCollection;
import com.kingdee.eas.basedata.master.cssp.SupplierCompanyInfoFactory;
import com.kingdee.eas.basedata.master.cssp.SupplierCompanyInfoInfo;
import com.kingdee.eas.basedata.master.cssp.SupplierFactory;
import com.kingdee.eas.basedata.master.cssp.SupplierGroupDetail;
import com.kingdee.eas.basedata.master.cssp.SupplierGroupDetailFactory;
import com.kingdee.eas.basedata.master.cssp.SupplierGroupDetailInfo;
import com.kingdee.eas.basedata.master.cssp.SupplierInfo;
import com.kingdee.eas.basedata.master.cssp.UsedStatusEnum;
import com.kingdee.eas.basedata.org.CompanyOrgUnitFactory;
import com.kingdee.eas.basedata.org.CompanyOrgUnitInfo;
import com.kingdee.eas.basedata.org.CtrlUnitFactory;
import com.kingdee.eas.basedata.org.CtrlUnitInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.cp.bc.BizAccountBillFactory;
import com.kingdee.eas.cp.bc.BizAccountBillInfo;
import com.kingdee.eas.cp.bc.IBizAccountBill;
import com.kingdee.eas.custom.jiu.IVoucherFoundMsg;
import com.kingdee.eas.custom.jiu.VoucherFoundMsgCollection;
import com.kingdee.eas.custom.jiu.VoucherFoundMsgFactory;
import com.kingdee.eas.custom.jiu.VoucherFoundMsgInfo;
import com.kingdee.eas.custom.jiu.VoucherPortMsgEntryInfo;
import com.kingdee.eas.custom.jiu.VoucherPortMsgFactory;
import com.kingdee.eas.custom.jiu.VoucherPortMsgInfo;
import com.kingdee.eas.custom.significance.app.UserMsgHelp;
import com.kingdee.eas.custom.voucher.EASLogin.EASLoginProxy;
import com.kingdee.eas.custom.voucher.EASLogin.EASLoginProxyServiceLocator;
import com.kingdee.eas.custom.voucher.WSGLWebServiceFacade.WSGLWebServiceFacadeSrvProxy;
import com.kingdee.eas.custom.voucher.WSGLWebServiceFacade.WSGLWebServiceFacadeSrvProxyServiceLocator;
import com.kingdee.eas.custom.voucher.client.WSContext;
import com.kingdee.eas.custom.voucher.client.WSInvokeException;
import com.kingdee.eas.custom.voucher.client.WSWSVoucher;
import com.kingdee.eas.fi.gl.IVoucher;
import com.kingdee.eas.fi.gl.VoucherAssistRecordInfo;
import com.kingdee.eas.fi.gl.VoucherCollection;
import com.kingdee.eas.fi.gl.VoucherEntryInfo;
import com.kingdee.eas.fi.gl.VoucherFactory;
import com.kingdee.eas.fi.gl.VoucherInfo;
import com.kingdee.eas.fi.gl.client.VoucherUtil;
import com.kingdee.eas.fm.common.FMIsqlFacadeFactory;
import com.kingdee.eas.fm.common.IFMIsqlFacade;
import com.kingdee.eas.framework.EffectedStatusEnum;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.util.NumericExceptionSubItem;
import com.kingdee.util.UuidException;


public class VoucherPortFacadeControllerBean extends AbstractVoucherPortFacadeControllerBean
{
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static Logger logger =
        Logger.getLogger("com.kingdee.eas.custom.jiu.app.VoucherPortFacadeControllerBean");
    
    //管理单元
	private CtrlUnitInfo ctrlUnitInfo=null;
	//财务组织
	private CompanyOrgUnitInfo orgUnitInfo=null; 
	private UserInfo userInfo=null;
	//科目表编码
	private String accountTableNumber="002";

	private String companyNumber="02";
	
	private String userNumber="user";


	//数据同步
	protected void _syncBaseData(Context ctx, int type) throws BOSException, EASBizException
	 {
		logger.info("调用同步申康接口");
		ctrlUnitInfo=CtrlUnitFactory.getLocalInstance(ctx).getCtrlUnitInfo("select id,number,name where number='"+companyNumber+"'");
		userInfo=UserFactory.getLocalInstance(ctx).getUserInfo("select id ,number ,name where number='"+userNumber+"'");
		orgUnitInfo=CompanyOrgUnitFactory.getLocalInstance(ctx).getCompanyOrgUnitInfo("select id ,number ,name where number='"+companyNumber+"'");
		if(type==0||type==6){
			//同步同步自定核算项目类型
			addAsstActType(ctx);
		}
		if(type==1||type==6){
			//同步科目辅助账类型
			addAcctType(ctx);
		}
		if(type==2||type==6){
			//同步系统核算项目（供应商，银行账号）
			addSystemAcctTypeDetail(ctx);
			
			//同步自定核算项目
			addAcctTypeDetail(ctx);
		}
		if(type==3||type==6){
			//同步会计科目3
			addAccounts(ctx);
		}
	}
	
	/**
	 * 同步系统核算项目（供应商，银行账号）
	 * @param ctx
	 * @throws BOSException 
	 * @throws ServiceException 
	 * @throws RemoteException 
	 * @throws WSInvokeException 
	 * @throws EASBizException 
	 */
	private void addSystemAcctTypeDetail(Context ctx){
		int addCount=0;
		int updateCount=0;
		VoucherPortMsgInfo msgInfo=new VoucherPortMsgInfo();
		msgInfo.setName("同步系统核算项目（供应商，银行账号）");
		String[][] acctType;
		try {
			acctType = getAcctType(ctx);
		
			if(!isEASLogin(ctx)){
				throw new RuntimeException("登录验证失败");
			}

			if(acctType==null||acctType.length==0){
				throw new RuntimeException("未找到辅助账类型");
			}
			WSGLWebServiceFacadeSrvProxyServiceLocator locator=new WSGLWebServiceFacadeSrvProxyServiceLocator();
			WSGLWebServiceFacadeSrvProxy facadeSrvProxy = locator.getWSGLWebServiceFacade();
			String acctTypeNumber=null;
			String[][] asstActType=null;
			//辅助账类型中存在相同的核算项目类型，将处理过的核算项目类型保存在numberList判断是否已经处理过
			List<String> numberList=new ArrayList<String>();
			
			SelectorItemCollection itemCollection=new SelectorItemCollection();
			itemCollection.add(new SelectorItemInfo("name"));
			
			Map<String, CSSPGroupInfo> map=new HashMap<String, CSSPGroupInfo>();
			CSSPGroupCollection cSSPGroupCollection = CSSPGroupFactory.getLocalInstance(ctx).getCSSPGroupCollection();
			for(int i=0;i<cSSPGroupCollection.size();i++){
				CSSPGroupInfo info=cSSPGroupCollection.get(i);
				map.put(info.getNumber(), info);
			}
			
			CSSPGroupStandardInfo cSSPGroupStandardInfo=new CSSPGroupStandardInfo();
			CSSPGroupStandardCollection cSSPGroupStandardCollection = CSSPGroupStandardFactory.getLocalInstance(ctx).getCSSPGroupStandardCollection("where type=2 and ISBASIC=1");
			if(cSSPGroupStandardCollection.size()>0){
				cSSPGroupStandardInfo=cSSPGroupStandardCollection.get(0);
			}
			
			ISupplier iSupplier = SupplierFactory.getLocalInstance(ctx);
			IAccountBank iAccountBank = AccountBankFactory.getLocalInstance(ctx);
			IFMIsqlFacade iFMIsqlFacade = FMIsqlFacadeFactory.getLocalInstance(ctx);
			ISupplierCompanyInfo iSupplierCompanyInfo = SupplierCompanyInfoFactory.getLocalInstance(ctx);
			for(int i=1;i<acctType.length;i++){
				acctTypeNumber = acctType[i][24];
				asstActType=facadeSrvProxy.getAsstActType(UserMsgHelp.COMPANY, acctTypeNumber);
				for(int j=0;j<asstActType.length;j++){
					System.out.println("asstActType:"+asstActType[j][7]);
					//不重复处理
					if(numberList.contains(asstActType[j][1])){
						continue;
					}
					numberList.add(asstActType[j][1]);
					
					//供应商
					if("T_BD_Supplier".equals(asstActType[j][7])){
						String[][] acctTypeDetail = facadeSrvProxy.getAcctTypeDetail(UserMsgHelp.COMPANY,asstActType[j][1]);
						for(int k=1;k<acctTypeDetail.length;k++){
							String name=acctTypeDetail[k][0];
							String number=acctTypeDetail[k][1];
							SupplierCollection collection = iSupplier.getSupplierCollection("where number='"+number+"'");
							if(collection.size()>0){
								SupplierInfo info = collection.get(0);
								info.setName(name);
								
								try {
									iSupplier.updatePartial(info, itemCollection);
									updateCount++;
								} catch (Exception e) {
									addMsgEntry(msgInfo,info.getNumber(),info.getName(),e.toString());
								} 
							}else{
								SupplierInfo info = new SupplierInfo();
								SupplierCompanyInfoInfo supplierCompanyInfoInfo=new SupplierCompanyInfoInfo();
								try {
									String key=number.substring(0, 4);
									if(map.containsKey(key)){
										info.setNumber(number);
										info.setName(name);
										info.setId(BOSUuid.create(info.getBOSType().toString()));
										info.setCreator(userInfo);
										info.setCU(ctrlUnitInfo);
										info.setUsedStatus(UsedStatusEnum.APPROVED);
										info.setEffectedStatus(EffectedStatusEnum.EFFECTED);
										info.setBrowseGroup(map.get(key));
										iSupplier.addnew(info);
										
										itemCollection=new SelectorItemCollection();
										itemCollection.add(new SelectorItemInfo("CU"));
										info.setCU(ctrlUnitInfo);
										iSupplier.updatePartial(info, itemCollection);
										
										//客户财务
										supplierCompanyInfoInfo.setCompanyOrgUnit(orgUnitInfo);
										supplierCompanyInfoInfo.setEffectedStatus(EffectedStatusEnum.EFFECTED);
										supplierCompanyInfoInfo.setCreator(userInfo);
										supplierCompanyInfoInfo.setCU(ctrlUnitInfo);
										supplierCompanyInfoInfo.setSupplier(info);
				    				    
										iSupplierCompanyInfo.addnew(supplierCompanyInfoInfo);
										
										String sql="insert into T_BD_SupplierGroupDetail (fid,FSupplierGroupStandardID,FSupplierGroupID,FSupplierID,FSupplierGroupFullName) " +
												"values (?,?,?,?,?);";
										Object[] paramArrayOfObject=new Object[]{BOSUuid.create("F3860252").toString(),cSSPGroupStandardInfo.getId().toString()
												,map.get(key).getId().toString(),info.getId().toString(),map.get(key).getName()};
										iFMIsqlFacade.executeSql(sql, paramArrayOfObject);
										addCount++;
									}
								} catch (Exception e) {
									addMsgEntry(msgInfo,info.getNumber(),info.getName(),e.toString());
								} 
								
							}
						}
					}
					
					//银行账号
					if("T_BD_AccountBanks".equals(asstActType[j][7])){
						String[][] acctTypeDetail = facadeSrvProxy.getAcctTypeDetail(UserMsgHelp.COMPANY,asstActType[j][1]);
						System.out.println(acctTypeDetail);
//						for(int k=1;k<acctTypeDetail.length;k++){
//							String name=acctTypeDetail[k][0];
//							String number=acctTypeDetail[k][1];
//							AccountBankCollection collection = iAccountBank.getAccountBankCollection("where number='"+number+"'");
//							if(collection.size()>0){
//								AccountBankInfo info = collection.get(0);
//								info.setName(name);
//								try {
//									iAccountBank.updatePartial(info, itemCollection);
//									updateCount++;
//								} catch (Exception e) {
//									addMsgEntry(msgInfo,info.getNumber(),info.getName(),e.toString());
//								} 
//							}else{
//								AccountBankInfo info = new AccountBankInfo();
//								try {
//									String key=number.substring(0, 4);
//									if(map.containsKey(key)){
//										info.setNumber(number);
//										info.setName(name);
//										info.setId(BOSUuid.read(info.getBOSType().toString()));
//										info.setCreator(userInfo);
//										info.setCU(ctrlUnitInfo);
//										iAccountBank.addnew(info);
//										
//										addCount++;
//									}
//								} catch (Exception e) {
//									addMsgEntry(msgInfo,info.getNumber(),info.getName(),e.toString());
//								} 
//								
//							}
//							
//						}
					}
					
				}
			}
		} catch (Exception e) {
			msgInfo.setDescription(e.toString());
		}
		//新增数量
		msgInfo.setAddCount(addCount);
		//修改数量
		msgInfo.setUpdateCount(updateCount);
		//添加日志
		addMsg( ctx, msgInfo);
	}
	

	/**
	 * 同步会计科目
	 * @param ctx
	 * @throws WSInvokeException
	 * @throws RemoteException
	 * @throws ServiceException
	 * @throws ParserException 
	 * @throws BOSException 
	 * @throws EASBizException 
	 */
	private void addAccounts(Context ctx){

		int addCount=0;
		int updateCount=0;
		VoucherPortMsgInfo msgInfo=new VoucherPortMsgInfo();
		msgInfo.setName("同步会计科目");
		AccountViewInfo oldInfo =null;

		try {
			List<AccountViewInfo> list=getAccount(ctx,msgInfo);
			AccountViewInfo info = null;
			AccountViewCollection accountViewCollection = null;
			IAccountView iaccountView = AccountViewFactory.getLocalInstance(ctx);

			SelectorItemCollection itemCollection=new SelectorItemCollection();

			for(int i=0;i<list.size();i++){
				itemCollection.clear();
				info = list.get(i);

				accountViewCollection = iaccountView.getAccountViewCollection("select id,number,name,CAA.id,AC,ACNotice,isOutDailyAccount,bw,isCash,isBank,isChangeCurrency,isCashEquivalent,accountingcurrency,gLevel,controlLevel where number='"+info.getNumber()+"' and CU.id='"+ctrlUnitInfo.getId()+"' and accountTableID.number='"+accountTableNumber+"'");
				if(accountViewCollection.size()>0){
					oldInfo = accountViewCollection.get(0);
					//名称
					if(!oldInfo.getName().equals(info.getName())){
						oldInfo.setName(info.getName());
						itemCollection.add(new SelectorItemInfo("name"));
					}

					//本级辅助账类型
					if(null==oldInfo.getCAA()&&null!=info.getCAA()){
						oldInfo.setCAA(info.getCAA());
						itemCollection.add(new SelectorItemInfo("CAA"));
					}else if(null!=oldInfo.getCAA()&&null==info.getCAA()){
						oldInfo.setCAA(null);
						itemCollection.add(new SelectorItemInfo("CAA"));
					}else if(null!=oldInfo.getCAA()&&null!=info.getCAA()){
						if(!oldInfo.getCAA().getId().toString().equals(info.getCAA().getId().toString())){
							oldInfo.setCAA(info.getCAA());
							itemCollection.add(new SelectorItemInfo("CAA"));
						}
					}

					//往来核算
					if(info.isAC()!=oldInfo.isAC()){
						oldInfo.setAC(info.isAC());
						itemCollection.add(new SelectorItemInfo("AC"));
					}
					//51往来通知
					if(info.isACNotice()!=oldInfo.isACNotice()){
						oldInfo.setACNotice(info.isACNotice());
						itemCollection.add(new SelectorItemInfo("ACNotice"));
					}
					//是否出日记帐
					if(info.isIsOutDailyAccount()!=oldInfo.isIsOutDailyAccount()){
						oldInfo.setIsOutDailyAccount(info.isIsOutDailyAccount());
						itemCollection.add(new SelectorItemInfo("isOutDailyAccount"));
					}
					//表外属性
					if(info.isBw()!=oldInfo.isBw()){
						oldInfo.setBw(info.isBw());
						itemCollection.add(new SelectorItemInfo("bw"));
					}
					//是否现金科目
					if(info.isIsCash()!=oldInfo.isIsCash()){
						oldInfo.setIsCash(info.isIsCash());
						itemCollection.add(new SelectorItemInfo("isCash"));
					}
					//是否银行科目
					if(info.isIsBank()!=oldInfo.isIsBank()){
						oldInfo.setIsBank(info.isIsBank());
						itemCollection.add(new SelectorItemInfo("isBank"));
					}
					//现金等价物
					if(info.isIsCashEquivalent()!=oldInfo.isIsCashEquivalent()){
						oldInfo.setIsCashEquivalent(info.isIsCashEquivalent());
						itemCollection.add(new SelectorItemInfo("isCashEquivalent"));
					}
					//是否期末调汇
					if(info.isIsChangeCurrency()!=oldInfo.isIsChangeCurrency()){
						oldInfo.setIsChangeCurrency(info.isIsChangeCurrency());
						itemCollection.add(new SelectorItemInfo("isChangeCurrency"));
					}
					//外币核算类型
					if(!info.getAccountingcurrency().equals(oldInfo.getAccountingcurrency())){
						oldInfo.setAccountingcurrency(info.getAccountingcurrency());
						itemCollection.add(new SelectorItemInfo("accountingcurrency"));
					}

					//控制下级级次
					if(info.getGLevel()!=oldInfo.getGLevel()){
						oldInfo.setGLevel(info.getGLevel());
						itemCollection.add(new SelectorItemInfo("gLevel"));
					}

					//本级控制级次
					if(info.getControlLevel()!=oldInfo.getControlLevel()){
						oldInfo.setControlLevel(info.getControlLevel());
						itemCollection.add(new SelectorItemInfo("controlLevel"));
					}
					//修改
					if(itemCollection.size()>0){
						try {
							iaccountView.updatePartial(oldInfo, itemCollection);
							updateCount++;
						} catch (Exception e) {
							String msg="";
							if(e.toString().length()>200){
								msg=e.toString().substring(0, 200);
							}else{
								msg=e.toString();
							}
							addMsgEntry(msgInfo,info.getNumber(), info.getName(),"修改失败："+msg);
						}
					}
				}else{
					//获取父级
					if(null!=info.get("parentNumber")){
						accountViewCollection = iaccountView.getAccountViewCollection("select id ,number,name where number='"+info.get("parentNumber")+"' and CU.id='"+ctrlUnitInfo.getId()+"' ");
						if(accountViewCollection.size()==0){
							addMsgEntry(msgInfo,info.getNumber(), info.getName(),"找不到父级科目"+info.get("parentNumber"));
							continue;	
						}
						info.setParent(accountViewCollection.get(0));
					}
					try {
						iaccountView.addnew(info);
						
						itemCollection = new SelectorItemCollection();
						itemCollection.add(new SelectorItemInfo("CU"));
						info.setCU(ctrlUnitInfo);
						iaccountView.updatePartial(info, itemCollection);
						
						addCount++;
					} catch (Exception e) {
						String msg="";
						if(e.toString().length()>200){
							msg=e.toString().substring(0, 200);
						}else{
							msg=e.toString();
						}
						addMsgEntry(msgInfo,info.getNumber(),"新增失败："+info.getName(),msg);
					} 
				}
			}
		} catch (Exception e) {
			String msg="";
			if(e.toString().length()>200){
				msg=e.toString().substring(0, 200);
			}else{
				msg=e.toString();
			}
			msgInfo.setDescription(msg);
		}
		msgInfo.setAddCount(addCount);
		msgInfo.setUpdateCount(updateCount);
		addMsg(ctx,msgInfo);
	}


	/**
	 * 获取科目辅助账类型
	 * @param ctx
	 * @return
	 * @throws BOSException 
	 */
	private Map<String,AsstAccountInfo> getAcctTypeMap(Context ctx) throws BOSException{
		Map<String,AsstAccountInfo> map=new HashMap<String, AsstAccountInfo>();
		IAsstAccount iasstAccount = AsstAccountFactory.getLocalInstance(ctx);
		AsstAccountCollection collection = iasstAccount.getAsstAccountCollection("select id ,number,name where CU.id='"+ctrlUnitInfo.getId()+"'");
		for(int i=0;i<collection.size();i++){
			map.put(collection.get(i).getNumber(),collection.get(i));
		}
		return map;
	}

	/**
	 * 获取科目类别
	 * @param ctx
	 * @param tableInfo
	 * @return
	 * @throws BOSException
	 */
	private Map<String,AccountTypeInfo>  AccountType(Context ctx,AccountTableInfo tableInfo) throws BOSException{
		//科目类型
		IAccountType iaccountType = AccountTypeFactory.getLocalInstance(ctx);
		AccountTypeCollection collection = iaccountType.getAccountTypeCollection("select id ,name,number where accountTableID.id='"+tableInfo.getId()+"'");
		Map<String,AccountTypeInfo> map=new HashMap<String, AccountTypeInfo>();

		for(int i=0;i<collection.size();i++){
			map.put(collection.get(i).getName(), collection.get(i));
		}
		return map;
	}

	/**
	 * 获取科目表
	 * @param ctx
	 * @return
	 * @throws BOSException 
	 * @throws ParserException 
	 */
	private AccountTableInfo getAccountTable(Context ctx) throws BOSException, ParserException{
		//科目表
		IAccountTable iaccountTable = AccountTableFactory.getLocalInstance(ctx);
		return iaccountTable.getAccountTableCollection(new EntityViewInfo("select id ,number ,name where number='"+accountTableNumber+"'")).get(0);
	}

	/**
	 * 获取科目数据
	 * @param ctx
	 * @throws RemoteException 
	 * @throws WSInvokeException 
	 * @throws ServiceException 
	 * @throws BOSException 
	 * @throws EASBizException 
	 * @throws ParserException 
	 */
	private List<AccountViewInfo> getAccount(Context ctx,VoucherPortMsgInfo msgInfo) throws WSInvokeException, RemoteException, ServiceException, EASBizException, BOSException, ParserException{

		//科目表
		AccountTableInfo accountTableInfo=getAccountTable(ctx);
		//科目类别
		Map<String,AccountTypeInfo> typeMap=AccountType(ctx,accountTableInfo);
		//辅助账类型
		Map<String, AsstAccountInfo> acctTypeMap = getAcctTypeMap(ctx);
		//币种
		CurrencyInfo currencyInfo = getCurrencyInfo(ctx);
		List<AccountViewInfo> list=new ArrayList<AccountViewInfo>();

		if(!isEASLogin(ctx)){
			return null;
		}
		boolean result=true;
		int fromRow=0;
		int toRow=1000;
		int num=1;
		while (result) {
			WSGLWebServiceFacadeSrvProxyServiceLocator locator=new WSGLWebServiceFacadeSrvProxyServiceLocator();
			WSGLWebServiceFacadeSrvProxy facadeSrvProxy = locator.getWSGLWebServiceFacade();
			String[][] account = facadeSrvProxy.getAccount(UserMsgHelp.COMPANY,fromRow,toRow);
			fromRow=toRow;
			toRow=toRow+(toRow*num);
			num++;
			msgInfo.setExecuteCount(account.length);
			printString(account);
			if(account.length!=1001){
				result=false;
			}
			if(num==100){
				result=false;
			}
			for(int i=1;i<account.length;i++){
				AccountViewInfo info=new AccountViewInfo();
				//编码
				info.setNumber(account[i][0]);
				//名称
				info.setName(account[i][1]);
				//科目表2,3
				info.setAccountTableID(accountTableInfo);
				//科目类型
				if(!typeMap.containsKey(account[i][5])){
					addMsgEntry(msgInfo,info.getNumber(),info.getName(),"找不到科目类型:"+account[i][5]);
					//科目类型找不到
					continue;
				}
				info.setAccountTypeID(typeMap.get(account[i][5]));
				//长名称
				info.setLongName(account[i][6]);
				//父级
				if(null!=account[i][7]){
					info.put("parentNumber", account[i][7]);
				}
				//上级辅助账类型
				if(null!=account[i][10]&&!"".equals(account[i][10])){
					if(acctTypeMap.containsKey(account[i][10])){
						info.setParentAA(acctTypeMap.get(account[i][10]));
					}else{
						addMsgEntry(msgInfo,info.getNumber(),info.getName(),"找不到上级辅助类型"+account[i][11]);
						continue;
					}

				}
				//本级辅助账类型
				if(null!=account[i][31]&&!"".equals(account[i][31])){
					if(acctTypeMap.containsKey(account[i][31])){
						info.setCAA(acctTypeMap.get(account[i][31]));
					}else{
						addMsgEntry(msgInfo,info.getNumber(),info.getName(),"找不到本级辅助账类型"+account[i][32]);
						continue;
					}
				}
				//助记码
				info.setHelpCode(account[i][13]);
				//公司
				info.setCompanyID(orgUnitInfo);
				//币种
				info.setCurrencyID(currencyInfo);
				//科目余额方向
				info.setDC(BalanceDirectionEnum.getEnum(Integer.parseInt(account[i][18])));
				//本级控制级次49
				info.setControlLevel(Integer.parseInt(account[i][49]));
				//上级控制级次39
				info.setGLevel(Integer.parseInt(account[i][39]));
				//受控系统
				info.setControl(AccountControlAttribute.getEnum(Integer.parseInt(account[i][30])));
				//损益类别
				info.setPLType(AccountPLType.getEnum(Integer.parseInt(account[i][29])));
				info.setIsCFreeze(false);
				info.setIsGFreeze(false);
				//往来核算
				if(Integer.parseInt(account[i][28])==0){
					info.setAC(false);
				}else{
					info.setAC(true);
				}
				//51往来通知
				if(Integer.parseInt(account[i][51])==0){
					info.setACNotice(false);
				}else{
					info.setACNotice(true);
				}
				//是否出日记帐
				if(Integer.parseInt(account[i][50])==0){
					info.setIsOutDailyAccount(false);
				}else{
					info.setIsOutDailyAccount(true);
				}
				//表外属性
				if(Integer.parseInt(account[i][52])==0){
					info.setBw(false);
				}else{
					info.setBw(true);
				}
				//是否现金科目
				if(Integer.parseInt(account[i][35])==0){
					info.setIsCash(false);
				}else{
					info.setIsCash(true);
				}
				//是否银行科目
				if(Integer.parseInt(account[i][34])==0){
					info.setIsBank(false);
				}else{
					info.setIsBank(true);
				}
				//现金等价物
				if(Integer.parseInt(account[i][20])==0){
					info.setIsCashEquivalent(false);
				}else{
					info.setIsCashEquivalent(true);
				}
				//是否期末调汇
				if(Integer.parseInt(account[i][19])==0){
					info.setIsChangeCurrency(false);
				}else{
					info.setIsChangeCurrency(true);
				}

				//允许公司增加下级科目
				info.setIsAllowCA(true);
				//外币核算类型
				info.setAccountingcurrency(AccountingCurrencyEnum.getEnum(Integer.parseInt(account[i][33])));

				//创建人
				info.setCreator(userInfo);
				//修改人
				info.setLastUpdateUser(userInfo);
				//cu
				info.setCU(ctrlUnitInfo);
				list.add(info);
			}
		}

		return list;
	}


	/**
	 * 获取币种
	 * @param ctx
	 * @return
	 * @throws BOSException
	 */
	private  CurrencyInfo getCurrencyInfo(Context ctx) throws BOSException{
		ICurrency icurrency = CurrencyFactory.getLocalInstance(ctx);
		return icurrency.getCurrencyCollection("select id,number,name where number='BB01'").get(0);
	}

	/**
	 * 增加科目类别
	 * @param ctx
	 * @param typeInfo
	 * @throws BOSException 
	 * @throws EASBizException 
	 */
	private void addAccountType(Context ctx,AccountTypeInfo typeInfo) throws EASBizException, BOSException{
		IAccountType iaccountType = AccountTypeFactory.getLocalInstance(ctx);
		IObjectPK addnew = iaccountType.addnew(typeInfo);
		typeInfo.setId(BOSUuid.read(addnew.toString()));
	}


	/**
	 * 同步自定义核算项目
	 * @param ctx
	 * @throws BOSException 
	 * @throws ServiceException 
	 * @throws RemoteException 
	 * @throws WSInvokeException 
	 * @throws EASBizException 
	 */
	private void addAcctTypeDetail(Context ctx){
		//获取自定义核算项目类型
		GeneralAsstActTypeGroupCollection collection=null;
		IGeneralAsstActType igeneralAsstActType=null;
		try {
//			String typeNumber = getGAATypeGroupNumber(ctx);
			IGeneralAsstActTypeGroup igeneralAsstActTypeGroup = GeneralAsstActTypeGroupFactory.getLocalInstance(ctx);
			collection = igeneralAsstActTypeGroup.getGeneralAsstActTypeGroupCollection("select id ,number,name where CU.id='"+ctrlUnitInfo.getId()+"'");
			igeneralAsstActType = GeneralAsstActTypeFactory.getLocalInstance(ctx);
		} catch (Exception e) {
			VoucherPortMsgInfo msgInfo=new VoucherPortMsgInfo();
			msgInfo.setName("同步自定义核算项目");
			msgInfo.setDescription(e.toString());
			addMsg(ctx,msgInfo);
		}

		List<GeneralAsstActTypeInfo> infoList = null;
		GeneralAsstActTypeInfo info = null;
		GeneralAsstActTypeInfo oldInfo = null;
		GeneralAsstActTypeCollection oldCollection=null;
		IObjectPK billid = null;
		SelectorItemCollection itemCollection=new SelectorItemCollection();
		itemCollection.add(new SelectorItemInfo("name"));

		for(int i=0;i<collection.size();i++){
			int addCount=0;
			int updateCount=0;
			VoucherPortMsgInfo msgInfo=new VoucherPortMsgInfo();
			msgInfo.setName("同步自定义核算项目:"+collection.get(i).getName());
			try {
				infoList = getAcctTypeDetail(ctx,collection.get(i));
				//执行数
				msgInfo.setExecuteCount(infoList.size());
				if(infoList!=null&&infoList.size()!=0){
					for(int j=0;j<infoList.size();j++){
						info= infoList.get(j);
						//将编码存储
						info.put("oldnumber", info.getNumber());
						//接口传递的编码  父级编码+编码
						getParentAcctTypeDetail(ctx,info,infoList,msgInfo);

						//长编码
						if(info.getNumber().indexOf(".")!=-1){
							oldCollection = igeneralAsstActType.getGeneralAsstActTypeCollection("select id ,number,name where longnumber='"+info.getNumber().replace(".", "!")+"' and  group.id='"+collection.get(i).getId()+"'");
						}else{
							oldCollection = igeneralAsstActType.getGeneralAsstActTypeCollection("select id ,number,name where longnumber='"+info.getNumber()+"' and group.id='"+collection.get(i).getId()+"'");
						}
						if(oldCollection.size()>0){
							oldInfo=oldCollection.get(0);
							if(!oldInfo.getName().equals(info.getName())){
								try {
									igeneralAsstActType.updatePartial(oldInfo, itemCollection);
									updateCount++;
								} catch (Exception e) {
									addMsgEntry(msgInfo,info.getNumber(),info.getName(),e.toString());
								} 
							}
							//id写入
							info.setId(oldInfo.getId());
						}else{
							try {
								//将编码中的父级编码和当前编码分开
								if(info.getNumber().indexOf(".")!=-1){
									info.setNumber(info.getNumber().substring(info.getNumber().lastIndexOf(".")+1));
								}
								billid = igeneralAsstActType.addnew(info);
								info.setId(BOSUuid.read(billid.toString()));
								
								itemCollection = new SelectorItemCollection();
								itemCollection.add(new SelectorItemInfo("CU"));
								info.setCU(ctrlUnitInfo);
								igeneralAsstActType.updatePartial(info, itemCollection);
								
								addCount++;
							} catch (Exception e) {
								addMsgEntry(msgInfo,info.getNumber(),info.getName(),e.toString());
							} 
						}
						//还原编码
						info.setNumber(info.get("oldnumber").toString());
					}
				}
			} catch (Exception e) {
				msgInfo.setDescription(e.toString());
			} 
			msgInfo.setAddCount(addCount);
			msgInfo.setUpdateCount(updateCount);
			addMsg(ctx,msgInfo);
		}
	}


	/**
	 * 修改父级节点isLeaf
	 * @param ctx
	 * @param info
	 * @param infoList
	 * @throws BOSException 
	 * @throws EASBizException
	 * @throws BOSException
	 */
	private void getParentAcctTypeDetail(Context ctx,GeneralAsstActTypeInfo info,List<GeneralAsstActTypeInfo> infoList,VoucherPortMsgInfo msgInfo) throws BOSException{

		GeneralAsstActTypeCollection generalAsstActTypeCollection =null;
		String number=info.getNumber();
		if(number.lastIndexOf(".")==-1){
			return;
		}
		int endIndex=number.lastIndexOf(".");
		//父级编码
		String parentNumber=number.substring(0, endIndex);
		GeneralAsstActTypeInfo parentInfo=null;
		for(int i=0;i<infoList.size();i++){
			parentInfo=infoList.get(i);
			if(parentInfo.getNumber().equals(parentNumber)){
				info.setParent(parentInfo);
				//判断父级是否更新过是否叶子节点字段
				if(parentInfo.get("leafUpdate")!=null){
					return;
				}
				//父级核算项目未添加成功
				if(parentInfo.getId()==null){
					addMsgEntry(msgInfo,info.getNumber(),info.getName(),"父级核算项目"+parentInfo.getNumber()+""+parentInfo.getName()+"不存在！");
					return;
				}
				IGeneralAsstActType igeneralAsstActType = GeneralAsstActTypeFactory.getLocalInstance(ctx);
				generalAsstActTypeCollection = igeneralAsstActType.getGeneralAsstActTypeCollection("select id,name,number,isLeaf where id='"+parentInfo.getId()+"'");
				//父级核算项目未添加成功
				if(generalAsstActTypeCollection.size()==0){
					addMsgEntry(msgInfo,info.getNumber(),info.getName(),"父级核算项目"+parentInfo.getNumber()+""+parentInfo.getName()+"不存在！");
					return;
				}
				if(parentInfo.isIsLeaf()){
					//修改父级
					SelectorItemCollection itemCollection=new SelectorItemCollection();
					itemCollection.add(new SelectorItemInfo("isLeaf"));
					parentInfo.setIsLeaf(false);
					try {
						igeneralAsstActType.updatePartial(parentInfo, itemCollection);
					} catch (Exception e) {
						addMsgEntry(msgInfo,info.getNumber(),info.getName(),"核算项目"+parentInfo.getNumber()+""+parentInfo.getName()+"存在子节点,修改当前节点isLeaf属性失败！");
					} 
					//标记父级已经更新过是否是否叶子节点字段
					parentInfo.put("leafUpdate", true);
				}
				return;
			}
		}
	}


	/**
	 * 同步自定义核算项目类型
	 * @param ctx
	 */
	private void addAsstActType(Context ctx){
		int addCount=0;
		int updateCount=0;
		VoucherPortMsgInfo msgInfo=new VoucherPortMsgInfo();
		msgInfo.setName("同步自定义核算项目类型");
		try {
			String[][] acctType=getAcctType(ctx);
			List<GeneralAsstActTypeGroupInfo> infoList= getAsstActType(ctx, acctType);
			IGeneralAsstActTypeGroup typeGroup = GeneralAsstActTypeGroupFactory.getLocalInstance(ctx);
			//执行数量
			msgInfo.setExecuteCount(infoList.size());
			GeneralAsstActTypeGroupInfo oldInfo = null;
			GeneralAsstActTypeGroupCollection collection=null;
			SelectorItemCollection itemCollection=new SelectorItemCollection();
			for(int i=0;i<infoList.size();i++){
				GeneralAsstActTypeGroupInfo info = infoList.get(i);
				collection= typeGroup.getGeneralAsstActTypeGroupCollection("select　name,number,description where CU.id='"+ctrlUnitInfo.getId()+"' and number='"+info.getNumber()+"'");
				if(collection.size()>0){
					itemCollection.clear();
					//对比
					oldInfo = collection.get(0);
					if(!oldInfo.getName().equals(info.getName())){
						itemCollection.add(new SelectorItemInfo("name"));
						oldInfo.setName(info.getName());
					}
					if(updateDescription(info,oldInfo)){
						itemCollection.add(new SelectorItemInfo("description"));
						oldInfo.setDescription(info.getDescription());
					}
					if(itemCollection.size()>0){
						try {
							typeGroup.updatePartial(oldInfo, itemCollection);
							updateCount++;
						}  catch (Exception e) {
							addMsgEntry(msgInfo,info.getNumber(),info.getName(),e.toString());
						}
					}
				}else{
					try {
						//新增
//						typeGroup.addnew(info);
						
						String sql="insert T_BD_GeneralAsstActTypeGroup (FID,FName_L2,FNumber,FDescription_L2,FShareTactic,FControlUnitID,FCreatorID,FLastUpdateUserID,FCreateTime,FLastUpdateTime) " +
						"values (?,?,?,?,?,?,?,?,getdate(),getdate())";
						List params = new ArrayList();
						params.add(BOSUuid.create("05D2CD0C").toString());
						params.add(info.getName());
						params.add(info.getNumber());
						params.add(info.getDescription());
						params.add(info.getShareTactic().getValue());
						params.add(info.getCU().getId().toString());
						params.add(info.getCreator().getId().toString());
						params.add(info.getLastUpdateUser().getId().toString());
						DbUtil.execute(ctx, sql, params.toArray());
						
						addCount++;
					}  catch (Exception e) {
						addMsgEntry(msgInfo,info.getNumber(),info.getName(),e.toString());
					}
				}
			}
			WSGLWebServiceFacadeSrvProxyServiceLocator locator=new WSGLWebServiceFacadeSrvProxyServiceLocator();
			WSGLWebServiceFacadeSrvProxy facadeSrvProxy = locator.getWSGLWebServiceFacade();
			IAsstActType iasstActType = AsstActTypeFactory.getLocalInstance(ctx);
			List<String> numberList=new ArrayList<String>();
			for(int i=1;i<acctType.length;i++){
				String acctTypeNumber = acctType[i][24];
				String[][] asstActType = facadeSrvProxy.getAsstActType(UserMsgHelp.COMPANY, acctTypeNumber);
				for(int j=1;j<asstActType.length;j++){
					System.out.println("asstActType:"+asstActType[j][0]+asstActType[j][7]);
//					//不处理非自定义的核算项目
//					if(!"T_BD_GeneralAsstActType".equals(asstActType[j][7])){
//						continue;
//					}
//					//不重复处理
//					if(numberList.contains(asstActType[j][1])){
//						continue;
//					}
//					numberList.add(asstActType[j][1]);
					
					AsstActTypeCollection asstActTypeCollection = iasstActType.getAsstActTypeCollection(new EntityViewInfo("select id where number='"+asstActType[j][1]+"'"));
					if(asstActTypeCollection.size()>0){
						AsstActTypeInfo asstActTypeinfo = asstActTypeCollection.get(0);
						itemCollection.add(new SelectorItemInfo("name"));
						asstActTypeinfo.setName(asstActType[j][0]);
						iasstActType.updatePartial(asstActTypeinfo, itemCollection);
					}else{
						AsstActTypeInfo asstActTypeInfo=new AsstActTypeInfo();
						asstActTypeInfo.setName(asstActType[j][0]);
						asstActTypeInfo.setNumber(asstActType[j][1]);
						asstActTypeInfo.setDescription(asstActType[j][2]);
						asstActTypeInfo.setSimpleName(asstActType[j][3]);
						asstActTypeInfo.setString("assistantType", asstActType[j][4]);
						asstActTypeInfo.setIsSelfAsstActaiatem(asstActType[j][5].equals("0")?false:true);
						asstActTypeInfo.setIsSystemAsstActItem(asstActType[j][6].equals("0")?false:true);
						asstActTypeInfo.setRealtionDataObject(asstActType[j][7]);
						asstActTypeInfo.setDefaultQueryName(asstActType[j][14]);
						asstActTypeInfo.setAsstHGAttribute(asstActType[j][15]);
						asstActTypeInfo.setMappingFieldName(asstActType[j][16]);
						asstActTypeInfo.setIsfreeze(asstActType[j][17].equals("0")?false:true);
						asstActTypeInfo.setIsForCompany(asstActType[j][18].equals("0")?false:true);
						asstActTypeInfo.setDefaultF7UI(asstActType[j][19]);
						asstActTypeInfo.setRealDataObjAlias(asstActType[j][20]);
						collection= typeGroup.getGeneralAsstActTypeGroupCollection("select　id,name,number,description where CU.id='"+ctrlUnitInfo.getId()+"' and number='"+asstActType[j][24]+"'");
						if(collection.size()>0){
							asstActTypeInfo.setGlAsstActTypeGrp(collection.get(0)); //自定义核算项目分组ID
						}
						
						asstActTypeInfo.setGroupTableName(asstActType[j][25]);
						asstActTypeInfo.setGroupMappingFieldName(asstActType[j][26]);
						asstActTypeInfo.setIsMultilevel(asstActType[j][27].equals("0")?false:true);
						asstActTypeInfo.setIsQty(asstActType[j][29].equals("0")?false:true);
						asstActTypeInfo.setPermissionItem(asstActType[j][28]);
//						asstActTypeInfo.setUseLongNumber(asstActType[j][34].equals("0")?false:true);
						asstActTypeInfo.setCU(ctrlUnitInfo);
						asstActTypeInfo.setCompany(orgUnitInfo);
						asstActTypeInfo.setCreator(userInfo);
						asstActTypeInfo.setLastUpdateUser(userInfo);
						
						iasstActType.addnew(asstActTypeInfo);
					}
				}
			}
			
		} catch (Exception e) {
			msgInfo.setDescription(e.toString());
		} 
		//新增数量
		msgInfo.setAddCount(addCount);
		//修改数量
		msgInfo.setUpdateCount(updateCount);
		//添加日志
		addMsg( ctx, msgInfo);
	}


	/**
	 *  同步科目辅助账类型
	 * @param ctx
	 */
	private void addAcctType(Context ctx){
		int addCount=0;
		int updateCount=0;
		VoucherPortMsgInfo msgInfo=new VoucherPortMsgInfo();
		msgInfo.setName("同步科目辅助账类型");

		try {
			List<AsstAccountInfo> acctTypeList = getAcctTypeList(ctx,msgInfo);
			//执行数
			msgInfo.setExecuteCount(acctTypeList.size());
			if(acctTypeList.size()==0){
				msgInfo.setDescription("获取自定义核算项目类型为0");
				addMsg(ctx,msgInfo);
				return;
			}

			IAsstAccount iasstAccount = AsstAccountFactory.getLocalInstance(ctx);
			IAsstActGroupDetail iactGroupDetail = AsstActGroupDetailFactory.getLocalInstance(ctx);

			AsstAccountInfo info = null;
			AsstAccountInfo oldInfo = null;
			AsstActGroupDetailCollection asstActGroupDetailCollection=null;
			boolean isUpdateEntry=false;

			for(int i=0;i<acctTypeList.size();i++){
				info = acctTypeList.get(i);
				AsstAccountCollection collection = iasstAccount.getAsstAccountCollection("select *,asstActGpDt.* where number='"+info.getNumber()+"'");
				if(collection.size()>0){
					oldInfo= collection.get(0);
					//对比
					if(!info.getName().trim().equals(oldInfo.getName().trim())){
						//修改操作
						oldInfo.setName(info.getName());
						isUpdateEntry=true;
					}
					//判断分录是否需要修改
					if(isUpdateAsstActGpDt(info,oldInfo)){
						oldInfo.getAsstActGpDt().clear();
						for(int j=0;j<info.getAsstActGpDt().size();j++){
							asstActGroupDetailCollection = iactGroupDetail.getAsstActGroupDetailCollection("select * where asstActType.number='"+info.getAsstActGpDt().get(j).getNumber()+"'");
							if(asstActGroupDetailCollection.size()==0){
								oldInfo.getAsstActGpDt().add(info.getAsstActGpDt().get(j));
							}else{
								oldInfo.getAsstActGpDt().add(asstActGroupDetailCollection.get(0));
							}
						}
						isUpdateEntry=true;
					}	
					if(isUpdateEntry){
						iasstAccount.save(info);
						updateCount++;
					}
				}else{
//					System.out.println("管理单元CU:"+ctrlUnitInfo.getName()+":"+ctrlUnitInfo.getNumber());
//					System.out.println("新增同步科目辅助账类型CU:"+info.getCU().getName()+":"+info.getCU().getNumber());
					iasstAccount.addnew(info);
					
					SelectorItemCollection itemCollection = new SelectorItemCollection();
					itemCollection.add(new SelectorItemInfo("CU"));
					info.setCU(ctrlUnitInfo);
					iasstAccount.updatePartial(info, itemCollection);
					addCount++;
				}
			}
		} catch (Exception e) {
			msgInfo.setDescription(e.toString());
		} 
		msgInfo.setAddCount(addCount);
		msgInfo.setUpdateCount(updateCount);
		addMsg(ctx,msgInfo);
	}


	/**
	 * 辅助账类型分录是否需要修改
	 * @param info
	 * @param oldInfo
	 * @return
	 */
	private boolean isUpdateAsstActGpDt(AsstAccountInfo info,AsstAccountInfo oldInfo){
		if(info.getAsstActGpDt()==null&&(null==oldInfo.getAsstActGpDt()||oldInfo.getAsstActGpDt().size()==0)){
			return false;
		}
		if(oldInfo.getAsstActGpDt()==null&&(null==info.getAsstActGpDt()||info.getAsstActGpDt().size()==0)){
			return false;
		}
		if(info.getAsstActGpDt().size()!=oldInfo.getAsstActGpDt().size()){
			return false;
		}
		String typeId=null;
		int count=0;
		for(int i=0;i<info.getAsstActGpDt().size();i++){
			typeId=info.getAsstActGpDt().get(i).getAsstActType().getId().toString();
			for(int j=0;j<oldInfo.getAsstActGpDt().size();j++){
				if(typeId.equals(oldInfo.getAsstActGpDt().get(j).getAsstActType().getId().toString())){
					count++;
					continue;
				}
			}
		}
		if(count!=info.getAsstActGpDt().size()){
			return true;
		}
		return false;
	}

	/**
	 * 获取科目辅助账类型
	 * @param ctx
	 * @throws ServiceException 
	 * @throws RemoteException 
	 * @throws WSInvokeException 
	 * @throws ServiceException 
	 * @throws RemoteException 
	 * @throws WSInvokeException 
	 * @throws BOSException 
	 * @throws BOSException 
	 * @throws ParserException 
	 * @throws ParserException 
	 */
	private List<AsstAccountInfo> getAcctTypeList(Context ctx,VoucherPortMsgInfo msgInfo) throws WSInvokeException, RemoteException, ServiceException, BOSException, ParserException{

		String[][] acctType = getAcctType(ctx);
		if(acctType==null){ 
			msgInfo.setDescription("获取科目辅助账类型0条！");
			return null;
		}
		
		List<AsstAccountInfo> list=new ArrayList<AsstAccountInfo>();
		WSGLWebServiceFacadeSrvProxyServiceLocator locator=new WSGLWebServiceFacadeSrvProxyServiceLocator();
		WSGLWebServiceFacadeSrvProxy facadeSrvProxy = locator.getWSGLWebServiceFacade();
		IAsstActType iasstActType = AsstActTypeFactory.getLocalInstance(ctx); 

		String number=null;
		String[][] asstActType=null;
		AsstActTypeCollection asstActTypeCollection =null;

		for(int i=1;i<acctType.length;i++){
			AsstAccountInfo info=new AsstAccountInfo();
			number = acctType[i][24];
			asstActType=facadeSrvProxy.getAsstActType(UserMsgHelp.COMPANY, number);
			
			//编码
			info.setNumber(number);
			//名称
			info.setName(acctType[i][0]);
			//描述
			info.setDescription(acctType[i][1]);
			//cu
			info.setCU(ctrlUnitInfo);
			//创建人
			info.setCreator(userInfo);
			//最后修改人
			info.setLastUpdateUser(userInfo);
			//创建财务组织
			info.setCompany(orgUnitInfo);
			//包含核算项目数量
			info.setCount(asstActType.length-1);
			boolean isAll=true;
			for(int j=1;j<asstActType.length;j++){
				AsstActGroupDetailInfo entryInfo=new AsstActGroupDetailInfo();
				asstActTypeCollection=iasstActType.getAsstActTypeCollection(new EntityViewInfo("select id where number='"+asstActType[j][1]+"'"));
				if(asstActTypeCollection.size()==0){
					isAll=false;
					addMsgEntry(msgInfo,info.getNumber(),info.getName(),"辅助账类型同步失败"+number+":未找到辅助核算项目"+asstActType[j][1]+","+asstActType[j][0]);
					continue;
				}
				//核算项目
				entryInfo.setAsstActType(asstActTypeCollection.get(0));
				
				//顺序号
				entryInfo.setSeq(j);
				info.getAsstActGpDt().add(entryInfo);
				
			}
			if(isAll){
				list.add(info);
			}
			
		}
		return list;
	}


	/**
	 * 判断辅助账类型中的核算项目是否全部为自定义核算项目
	 * @param asstActType
	 * @return
	 */
	private boolean isCustomAcctType(String[][] asstActType){
		for(int i=1;i<asstActType.length;i++){
			if(!"T_BD_GeneralAsstActType".equals(asstActType[i][7])){
				return false;
			}
		}
		return true;
	}




	private boolean updateDescription(GeneralAsstActTypeGroupInfo info ,GeneralAsstActTypeGroupInfo oldInfo ){
		if(info.getDescription()==null&&oldInfo.getDescription()!=null){
			return true;
		}else if(info.getDescription()!=null&&oldInfo.getDescription()==null){
			return true;
		}else if(info.getDescription()==null&&oldInfo.getDescription()==null){
			return false;
		}else if(!info.getDescription().equals(oldInfo.getDescription())){
			return true;
		}
		return false;
	}


	/**
	 * 获取公司辅助账类型
	 * @param ctx
	 * @return 公司全部辅助账类型
	 * @throws ServiceException 
	 * @throws RemoteException 
	 * @throws WSInvokeException 
	 */
	private String[][] getAcctType(Context ctx) throws ServiceException, WSInvokeException, RemoteException{
		if(!isEASLogin(ctx)){
			return null;
		}
		WSGLWebServiceFacadeSrvProxyServiceLocator locator=new WSGLWebServiceFacadeSrvProxyServiceLocator();
		WSGLWebServiceFacadeSrvProxy facadeSrvProxy = locator.getWSGLWebServiceFacade();
		return facadeSrvProxy.getAcctType(UserMsgHelp.COMPANY);
	}



	/**
	 * 获取自定义核算项目类型
	 * @param ctx
	 * @param acctType
	 * @return
	 * @throws RemoteException 
	 * @throws WSInvokeException 
	 * @throws ServiceException 
	 * @throws RemoteException 
	 * @throws WSInvokeException 
	 * @throws ServiceException 
	 */
	private List<GeneralAsstActTypeGroupInfo> getAsstActType(Context ctx,String[][] acctType) throws WSInvokeException, RemoteException, ServiceException {
		if(!isEASLogin(ctx)){
			return null;
		}
		if(acctType==null||acctType.length==0){
			return null;
		}
		List<GeneralAsstActTypeGroupInfo> listInfo=new ArrayList<GeneralAsstActTypeGroupInfo>();
		WSGLWebServiceFacadeSrvProxyServiceLocator locator=new WSGLWebServiceFacadeSrvProxyServiceLocator();
		WSGLWebServiceFacadeSrvProxy facadeSrvProxy = locator.getWSGLWebServiceFacade();
		String acctTypeNumber=null;
		String[][] asstActType=null;
		//辅助账类型中存在相同的核算项目类型，将处理过的核算项目类型保存在numberList判断是否已经处理过
		List<String> numberList=new ArrayList<String>();
		GeneralAsstActTypeGroupInfo typeGroupInfo=null;


		for(int i=1;i<acctType.length;i++){
			acctTypeNumber = acctType[i][24];
			asstActType=facadeSrvProxy.getAsstActType(UserMsgHelp.COMPANY, acctTypeNumber);
			for(int j=0;j<asstActType.length;j++){
				System.out.println("asstActType:"+asstActType[j][7]);
				//不处理非自定义的核算项目
				if(!"T_BD_GeneralAsstActType".equals(asstActType[j][7])){
					continue;
				}
				//不重复处理
				if(numberList.contains(asstActType[j][1])){
					continue;
				}
				typeGroupInfo=new GeneralAsstActTypeGroupInfo();
				//名称
				typeGroupInfo.setName(asstActType[j][0]);
				//编码
				typeGroupInfo.setNumber(asstActType[j][1]);
				//描述
				typeGroupInfo.setDescription(asstActType[j][2]);
				//共享类型
				typeGroupInfo.setShareTactic(ShareTacticEnum.I);
				//cu
				typeGroupInfo.setCU(ctrlUnitInfo);
				//创建人
				typeGroupInfo.setCreator(userInfo);
				//修改人
				typeGroupInfo.setLastUpdateUser(userInfo);

				numberList.add(asstActType[j][1]);
				listInfo.add(typeGroupInfo);
				
			}
		}
		return listInfo;
	}


	private void printString(String[][] strings){
		for(int i=0;i<strings.length;i++){
			System.out.println();
			String[] accouts = strings[i];
			String msg=null;
			for(int j=0;j<accouts.length;j++){
				String values = accouts[j];
				if(j==0){
					msg=values;
				}else{
					msg=msg+","+values;
				}
			}
			System.out.print(msg+",");
		}
	}



	/**
	 * 获取自定义核算项目
	 * @param ctx
	 * @param number 自定义核算项目类型编码
	 * @return
	 * @throws WSInvokeException
	 * @throws RemoteException
	 * @throws ServiceException
	 */
	private List<GeneralAsstActTypeInfo> getAcctTypeDetail(Context ctx,GeneralAsstActTypeGroupInfo groupInfo) throws WSInvokeException, RemoteException, ServiceException{
		if(!isEASLogin(ctx)){
			return null;
		}
		List<GeneralAsstActTypeInfo> list=new ArrayList<GeneralAsstActTypeInfo>();
		WSGLWebServiceFacadeSrvProxyServiceLocator locator=new WSGLWebServiceFacadeSrvProxyServiceLocator();
		WSGLWebServiceFacadeSrvProxy facadeSrvProxy = locator.getWSGLWebServiceFacade();
		String[][] acctTypeDetail = facadeSrvProxy.getAcctTypeDetail(UserMsgHelp.COMPANY,groupInfo.getNumber());
		if(acctTypeDetail==null){
			return null;
		}
		System.out.println(groupInfo.getNumber());
		printString(acctTypeDetail);
		for(int i=1;i<acctTypeDetail.length;i++){
			GeneralAsstActTypeInfo info=new GeneralAsstActTypeInfo();
			//分组
			info.setGroup(groupInfo);
			//创建人
			info.setCreator(userInfo);
			//修改人
			info.setLastUpdateUser(userInfo);
			//cu
			info.setCU(ctrlUnitInfo);
			//创建公司
			info.setCreatorCompany(orgUnitInfo);
			//编码
			info.setName(acctTypeDetail[i][0]);
			//名称
			info.setNumber(acctTypeDetail[i][1]);
			list.add(info);
		}
		return list;
	}
	//用户登录
	public boolean isEASLogin(Context ctx){
		try {
			EASLoginProxyServiceLocator	locator=new EASLoginProxyServiceLocator();
			EASLoginProxy easLogin = locator.getEASLogin();
			WSContext login = easLogin.login(UserMsgHelp.USERNO, UserMsgHelp.USERPASS, "eas", UserMsgHelp.DCNAME, "L2", UserMsgHelp.DBTYPE);
			if(login.getSessionId()!=null){
				logger.info("成功接入盛康EAS系统！");
				return true;
			}else{
				addEASLoginMsg(ctx,"登陆盛康EAS系统失败！");
			}
		} catch (Exception e) {
			addEASLoginMsg(ctx,"登陆盛康EAS系统失败！");
		} 
		logger.info("接入盛康EAS系统失败！");
		return false;
	}


	/**
	 * 增加日志
	 */
	private void addEASLoginMsg(Context ctx,String msg){
		try {
			VoucherPortMsgInfo info=new VoucherPortMsgInfo();
			info.setName("登录接口");
			info.setNumber(new Date().getTime()+"");
			info.setExecuteDate(new Date());
			info.setDescription(msg);
			VoucherPortMsgFactory.getLocalInstance(ctx).addnew(info);
		} catch (EASBizException e) {
			e.printStackTrace();
		} catch (BOSException e) {
			e.printStackTrace();
		}
	}

	private void addMsg(Context ctx,VoucherPortMsgInfo info){
		try {
			info.setNumber(new Date().getTime()+"");
			info.setExecuteDate(new Date());
			if(null!=info.getEntry()&&info.getEntry().size()>0){
				info.setDefeatedCount(info.getEntry().size());
			}else{
				info.setDefeatedCount(0);
			}
			VoucherPortMsgFactory.getLocalInstance(ctx).addnew(info);
		} catch (EASBizException e) {
			e.printStackTrace();
		} catch (BOSException e) {
			e.printStackTrace();
		}
	}

	private void addMsgEntry(VoucherPortMsgInfo info,String number,String name,String msg){
		VoucherPortMsgEntryInfo entryInfo=new VoucherPortMsgEntryInfo();
		entryInfo.setName(name);
		entryInfo.setNumber(number);
		entryInfo.setErrorlog(msg);
		info.getEntry().add(entryInfo);
	}





	/**
	 * 增加凭证接口辅助账数据
	 * @param ctx
	 * @param voucher 凭证接口对象
	 * @param asstActGpDt 科目辅助账明细
	 * @param assistRecordInfo 凭证辅助账
	 * @throws BOSException
	 * @throws EASBizException
	 */
	private void addAssistantHGInfo(Context ctx,WSWSVoucher voucher,AsstActGroupDetailCollection asstActGpDt,AssistantHGInfo assGrp) throws BOSException, EASBizException{
		IAssistantHG iassistantHG = AssistantHGFactory.getLocalInstance(ctx);
		//辅助账明细
		AsstActGroupDetailInfo asstActGroupDetailInfo =null;
		AssistantHGInfo newAssistantHGInfo = null;
		for(int j=0;j<asstActGpDt.size();j++){
			asstActGroupDetailInfo = asstActGpDt.get(j);
			//核算项目类型在横表中对应的字段名称
			String cellName=asstActGroupDetailInfo.getAsstActType().getAsstHGAttribute();
			String tableName=asstActGroupDetailInfo.getAsstActType().getRealtionDataObject();
			//表名称
			String number=null;
			String name=null;
			if("T_BD_GeneralAsstActType".equals(tableName)){
				newAssistantHGInfo = iassistantHG.getAssistantHGInfo("select "+cellName+".name,"+cellName+".longnumber where id='"+assGrp.getId()+"'");
				number=((IObjectValue)newAssistantHGInfo.get(cellName)).get("longnumber").toString().replace("!", ".");
				name=((IObjectValue)newAssistantHGInfo.get(cellName)).get("name").toString();
			}else{
				newAssistantHGInfo = iassistantHG.getAssistantHGInfo("select "+cellName+".name,"+cellName+".number where id='"+assGrp.getId()+"'");
				number=((IObjectValue)newAssistantHGInfo.get(cellName)).get("number").toString();
				name=((IObjectValue)newAssistantHGInfo.get(cellName)).get("name").toString();
			}

			if(asstActGroupDetailInfo.getSeq()==1){
				voucher.setAsstActType1(asstActGroupDetailInfo.getAsstActType().getName());
				voucher.setAsstActName1(name);
				voucher.setAsstActNumber1(number);
			}else if(asstActGroupDetailInfo.getSeq()==2){
				voucher.setAsstActType2(asstActGroupDetailInfo.getAsstActType().getName());
				voucher.setAsstActName2(name);
				voucher.setAsstActNumber2(number);
			}else if(asstActGroupDetailInfo.getSeq()==3){
				voucher.setAsstActType3(asstActGroupDetailInfo.getAsstActType().getName());
				voucher.setAsstActName3(name);
				voucher.setAsstActNumber3(number);
			}else if(asstActGroupDetailInfo.getSeq()==4){
				voucher.setAsstActType4(asstActGroupDetailInfo.getAsstActType().getName());
				voucher.setAsstActName4(name);
				voucher.setAsstActNumber4(number);
			}else if(asstActGroupDetailInfo.getSeq()==5){
				voucher.setAsstActType5(asstActGroupDetailInfo.getAsstActType().getName());
				voucher.setAsstActName5(name);
				voucher.setAsstActNumber5(number);
			}else if(asstActGroupDetailInfo.getSeq()==6){
				voucher.setAsstActType6(asstActGroupDetailInfo.getAsstActType().getName());
				voucher.setAsstActName6(name);
				voucher.setAsstActNumber6(number);
			}else if(asstActGroupDetailInfo.getSeq()==7){
				voucher.setAsstActType7(asstActGroupDetailInfo.getAsstActType().getName());
				voucher.setAsstActName7(name);
				voucher.setAsstActNumber7(number);
			}else if(asstActGroupDetailInfo.getSeq()==8){
				voucher.setAsstActType8(asstActGroupDetailInfo.getAsstActType().getName());
				voucher.setAsstActName8(name);
				voucher.setAsstActNumber8(number);
			}
		}
	}

	/**
	 * 封装凭证接口分录数据
	 * @param entryInfo
	 * @param voucher
	 */
	private void addwebVoucherEntry(VoucherEntryInfo entryInfo,WSWSVoucher voucher){
		//分录号
		voucher.setEntrySeq(entryInfo.getSeq());
		//凭证摘要
		voucher.setVoucherAbstract(entryInfo.getDescription());
		//科目编码
		voucher.setAccountNumber(entryInfo.getAccount().getNumber());
		//方向
		voucher.setEntryDC(entryInfo.getEntryDC().getValue());
		//原币金额
		voucher.setOriginalAmount(entryInfo.getOriginalAmount().doubleValue());
		if(entryInfo.getEntryDC().getValue()==1){
			//借方金额
			voucher.setDebitAmount(entryInfo.getOriginalAmount().doubleValue());
		}else{
			//贷方金额
			voucher.setCreditAmount(entryInfo.getOriginalAmount().doubleValue());
		}
		//币种
		voucher.setCurrencyNumber(entryInfo.getCurrency().getNumber());
		//汇率
		voucher.setLocalRate(entryInfo.getLocalExchangeRate().doubleValue());
	}

	/**
	 * 封装凭证接口主表数据
	 * @param voucherInfo
	 * @param voucher
	 */
	private void addWebVoucherInfo(VoucherInfo voucherInfo,WSWSVoucher voucher){
		SimpleDateFormat dateFormat=new  SimpleDateFormat("yyyy-MM-dd");
		//公司编码
		voucher.setCompanyNumber(UserMsgHelp.COMPANY);
		//记账日期
		voucher.setBookedDate(dateFormat.format(voucherInfo.getBookedDate()));
		//业务日期
		voucher.setBizDate(dateFormat.format(voucherInfo.getBizDate()));
		//期间
		voucher.setPeriodYear(voucherInfo.getPeriod().getPeriodYear());
		//期间编码
		voucher.setPeriodNumber(voucherInfo.getPeriod().getPeriodNumber());
		//凭证类型
		voucher.setVoucherType("记");
		//凭证号
		voucher.setVoucherNumber(voucherInfo.getNumber());
		//参考信息
//		voucher.setDescription("九院凭证号："+voucherInfo.getNumber());
		voucher.setDescription(voucherInfo.getDescription());
		//制单人
		voucher.setCreator(UserMsgHelp.USERNAME);
		//附件数量
		voucher.setAttaches(voucherInfo.getAttachments());

	}


	/**
	 * 获取凭证分录科目的核算项目明细
	 * @param ctx
	 * @param accountViewId 凭证分录id
	 * @return
	 * @throws BOSException 
	 * @throws EASBizException 
	 */
	private AsstActGroupDetailCollection getAsstActGpDt(Context ctx,VoucherEntryInfo entryInfo) throws BOSException, EASBizException{
		IAccountView iaccountView = AccountViewFactory.getLocalInstance(ctx);
		AccountViewInfo accountViewInfo = iaccountView.getAccountViewInfo("select CAA.asstActGpDt.asstActType.name ,CAA.asstActGpDt.asstActType.asstHGAttribute ,CAA.asstActGpDt.seq ,CAA.asstActGpDt.asstActType.realtionDataObject where id='"+entryInfo.getAccount().getId()+"'");
		if(accountViewInfo.getCAA()==null){
			return null;
		}
		return accountViewInfo.getCAA().getAsstActGpDt();
	}

	/**
	 * 获取凭证接口对象数组长度
	 * @param voucherInfo
	 * @return
	 */
	private int getVoucherLength(VoucherInfo voucherInfo ){
		int count=0;
		for(int i=0;i<voucherInfo.getEntries().size();i++){
			if(voucherInfo.getEntries().get(i).getAssistRecords().size()!=0){
				count=count+voucherInfo.getEntries().get(i).getAssistRecords().size();
			}else{
				count++;
			}
		}
		return count;
	}

	/**
	 * 获取凭证查询条件和字段范围
	 * @param voucherId
	 * @return
	 */
	private EntityViewInfo getVoucherEntityViewInfo(IObjectPK voucherId){
		EntityViewInfo viewInfo=new  EntityViewInfo();

		FilterInfo filter=new FilterInfo();
		filter.getFilterItems().add(new  FilterItemInfo("id",voucherId));
		viewInfo.setFilter(filter);

		SelectorItemCollection itemCollection=new SelectorItemCollection();

		itemCollection.add(new SelectorItemInfo("number"));
		itemCollection.add(new SelectorItemInfo("bookedDate"));
		itemCollection.add(new SelectorItemInfo("bizDate"));
		itemCollection.add(new SelectorItemInfo("description"));
		itemCollection.add(new SelectorItemInfo("attachments"));

		itemCollection.add(new SelectorItemInfo("period.periodYear"));
		itemCollection.add(new SelectorItemInfo("period.periodNumber"));

		itemCollection.add(new SelectorItemInfo("entries.seq"));
		itemCollection.add(new SelectorItemInfo("entries.description"));
		itemCollection.add(new SelectorItemInfo("entries.originalAmount"));
		itemCollection.add(new SelectorItemInfo("entries.entryDC"));
		itemCollection.add(new SelectorItemInfo("entries.account.id"));
		itemCollection.add(new SelectorItemInfo("entries.account.number"));
		itemCollection.add(new SelectorItemInfo("entries.currency.number"));
		itemCollection.add(new SelectorItemInfo("entries.localExchangeRate"));

		itemCollection.add(new SelectorItemInfo("entries.assistRecords.bizNumber"));
		itemCollection.add(new SelectorItemInfo("entries.assistRecords.assGrp.*"));
		itemCollection.add(new SelectorItemInfo("entries.assistRecords.originalAmount"));


		viewInfo.setSelector(itemCollection);

		return viewInfo;
	}


	/**
	 * 推送凭证数据到申康
	 */
	protected IObjectValue _impVoucher(Context ctx, IObjectPK voucherId)
	throws BOSException, EASBizException {

		String billNumber=null;
		String billDescription=null;
		IObjectPK msgId ;
		try {
			
			VoucherFoundMsgCollection VoucherFoundMsgCollection = VoucherFoundMsgFactory.getLocalInstance(ctx).getVoucherFoundMsgCollection("where name='"+voucherId+"' and isSucceed=1 ");
			if(VoucherFoundMsgCollection.size()>0){
				throw new EASBizException(new NumericExceptionSubItem("","已生成申康凭证，无需重复生成！")); 
			}
			
			IVoucher ivoucher = VoucherFactory.getLocalInstance(ctx);
			VoucherCollection voucherCollection = ivoucher.getVoucherCollection(getVoucherEntityViewInfo(voucherId));

			if(voucherCollection.size()==0){
				throw new EASBizException(new NumericExceptionSubItem("","凭证不存在！")); 
			}
			VoucherInfo voucherInfo = voucherCollection.get(0);
			if(!isEASLogin(ctx)){
				throw new EASBizException(new NumericExceptionSubItem("","登录申康系统失败！")); 
			}

			billNumber=voucherInfo.getNumber();
			billDescription=voucherInfo.getDescription();
			//凭证接口对象长度
			WSWSVoucher[] vouchers=new WSWSVoucher[getVoucherLength(voucherInfo)];

			VoucherEntryInfo entryInfo = null;
			AsstActGroupDetailCollection asstActGpDt = null;
			int count=0;
			WSWSVoucher voucher=null;
			VoucherAssistRecordInfo assistRecordInfo = null;

			for(int i=0;i<voucherInfo.getEntries().size();i++){
				//凭证分录
				entryInfo = voucherInfo.getEntries().get(i);
				//辅助账明细
				asstActGpDt = getAsstActGpDt(ctx,entryInfo);
				if(entryInfo.getAssistRecords().size()>0){
					for(int r=0;r<entryInfo.getAssistRecords().size();r++){
						assistRecordInfo = entryInfo.getAssistRecords().get(r);
						//封装凭证接口对象
						voucher=new WSWSVoucher();
						//填充主表数据
						addWebVoucherInfo(voucherInfo,voucher);
						//填充分录数据
						addwebVoucherEntry(entryInfo,voucher);
						//填充辅助账数据
						addAssistantHGInfo(ctx,voucher,asstActGpDt,assistRecordInfo.getAssGrp());
						//填充金额字段
						voucher.setOriginalAmount(assistRecordInfo.getOriginalAmount().doubleValue());
						if(entryInfo.getEntryDC().getValue()==1){
							//借方金额
							voucher.setDebitAmount(assistRecordInfo.getOriginalAmount().doubleValue());
						}else{
							//贷方金额
							voucher.setCreditAmount(assistRecordInfo.getOriginalAmount().doubleValue());
						}
						//业务编号
						voucher.setBizNumber(assistRecordInfo.getBizNumber());
						
						vouchers[count]=voucher;
						count++;
					}
				}else{
					voucher=new WSWSVoucher();
					addWebVoucherInfo(voucherInfo,voucher);
					addwebVoucherEntry(entryInfo,voucher);
					vouchers[count]=voucher;
					count++;
				}
			}
			//调用凭证接口
			WSGLWebServiceFacadeSrvProxyServiceLocator locator=new WSGLWebServiceFacadeSrvProxyServiceLocator();
			WSGLWebServiceFacadeSrvProxy facadeSrvProxy = locator.getWSGLWebServiceFacade();
			String[] values=facadeSrvProxy.importVoucher(vouchers, 0, 0, 0);
			//增加日志
			msgId = addVoucherMsg(ctx,billNumber,billDescription,values,null,voucherId.toString());
		} catch (Exception e) {
			//增加日志
			msgId = addVoucherMsg(ctx,billNumber,billDescription,null, e.toString(),voucherId.toString());
			e.printStackTrace();
		}
		return VoucherFoundMsgFactory.getLocalInstance(ctx).getVoucherFoundMsgInfo(msgId);
	}

	/**
	 * 
	 * @param ctx
	 * @param billNumber
	 * @param billDescription
	 * @return 
	 */
	private IObjectPK addVoucherMsg(Context ctx,String billNumber,String billDescription,String[] values,String e,String voucherId){
		VoucherFoundMsgInfo msgInfo=new VoucherFoundMsgInfo();
		msgInfo.setNumber(new Date().getTime()+"");
		msgInfo.setJyNumber(billNumber);
		msgInfo.setVoucherCreateDate(new Date());
		msgInfo.setName(voucherId);
		if(null!=billDescription){
			msgInfo.setDescription(billDescription);
		}
		if(values!=null&&values.length!=0){
			msgInfo.setLogmsg(values[0]);
			String[] cellValue=values[0].split("\\|\\|");;
			if("0000".equals(cellValue[0])){
				msgInfo.setIsSucceed(true);
				msgInfo.setSkNumber(cellValue[5]);
				msgInfo.setSimpleName("凭证号"+cellValue[5]+"期间"+cellValue[2]+"年"+cellValue[3]+"期");
				msgInfo.setLogmsg("凭证上传申康系统成功，凭证号："+cellValue[5]);
			}else{
				msgInfo.setIsSucceed(false);
				msgInfo.setLogmsg(cellValue[4]);
			}
		}else{
			msgInfo.setIsSucceed(false);
			msgInfo.setLogmsg(e);
		}
		try {
			return VoucherFoundMsgFactory.getLocalInstance(ctx).addnew(msgInfo);
		} catch (EASBizException e1) {
			e1.printStackTrace();
		} catch (BOSException e1) {
			e1.printStackTrace();
		}
		return null;
	}

}